package com.fgchen.study.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class StaticAspect {
    @Pointcut("execution(static * com.fgchen.study.util..*(..))")
    public void pointcut() {}

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        Signature signature = joinPoint.getSignature();
        Class<?> staticClass = joinPoint.getSourceLocation().getWithinType();
        String method = signature.getName();

        System.out.println(String.format("intercept a static method: [%s.%s()]",
                staticClass.getName(), method));

        Object result = joinPoint.proceed();
        System.out.println(String.format("after invoking static method, result: [%s]", result));
        return "fake-uuid";
    }
}
